import { ReactNode } from 'react';

export type DataSource = {
  // 数据主键信息
  keyInfo: {
    key: string;
    value?: string | number;
  };
  paginationInfo?: {
    currentField: string; // 页码字段
    pageSizeField: string; // 页容字段
  };
  apiList: ApiList;
};
export type ApiList = Record<ApiType, ApiInfo>;
export type ApiType = 'list' | 'detail' | 'add' | 'update' | 'delete' | 'deleteBatch';
export type ApiInfo = {
  url: string;
  method: 'Get' | 'Post';
  afterScript: string;
  parameter?: any;
  body?: any;
};

export type EventInfo = {
  type: EventType;
  tableRecord?: TableRecord;
};
export type EventType = 'detail' | 'edit' | 'add' | 'update' | 'delete' | 'deleteBatch';
export type EventTableType = string; // eventReloadTable + 随机数
export type EventFormType = string; // eventReloadForm + 随机数

export type ProTableContexteValue = {
  tableInfo: ProTableInfo;
  setTableInfo: (proTableInfo: ProTableInfo) => void;
  formInfo: ProFormInfo;
  setFormInfo: (proFormInfo: ProFormInfo) => void;
};
export type ProTableInfo = any;
// 表格筛选
export type ProTableSearch = {
  pageNo?: number;
  pageSize?: number;
  state?: string; // 表格menu类型
  createStartTime?: string;
  createEndTime?: string;
};
// 表格菜单
export type ProTableMenuInfo = {
  activeKey: string;
  menus: ProTableMenuItem[];
};
export type ProTableMenuItem = {
  key: string;
  title: string;
  count: number;
};
export type TableRecord = {
  reactNode: React.ReactNode;
  record: any;
  index: number;
};
export type TablePagination = {
  dataList: any[];
  total: number;
};
export type TableColumn = any;
export type TableColumns = any[];

export type ProFormInfo = {
  forms: Forms;
  dataSource: DataSource;
  currentTableRecord?: any;
};
// https://www.cnblogs.com/Wayou/p/14787954.html Partial<Record<FormType, FormInfo>>;
export type Forms = Record<FormType, FormInfo>;
export type FormType = 'add' | 'edit' | 'detail'; // form 类型
export type FormInfo = {
  formConfig: any;
  formFields: any[];
};

export type ModalsInfoConfig = {
  modals: Modals;
};
export type Modals = Record<ModalType, ModalInfo>;
export type ModalType =
  ///开始删除
  | 'setting'
  /// 结束删除
  | 'add'
  | 'edit'
  | 'detail'; // modal 类型
export type ModalInfo = {
  title: string;
  open: boolean;
  width?: number | string;
  reactNode: ReactNode;
};
